package com.ly.service.impl;

import com.ly.dao.AccountDao;
import com.ly.entity.BankAccount;
import com.ly.service.AccountService;

import java.util.ArrayList;

/**
 * Author: LiYao
 * CreateTime: 2025-03-11 19:34
 * Description:
 * Version: 1.0
 */
public class AccountServiceImpl implements AccountService {
    private final AccountDao accountDao = new AccountDao();

//    public void addAccount(BankAccount bankAccount) {
//        accountDao.addAccount(bankAccount);
//    }
//
//    public void deleteAccount(String accountID) {
//        accountDao.deleteAccount(accountID);
//    }

    @Override
    public BankAccount login(String accountID, String password) {
        ArrayList<BankAccount> accountList = accountDao.getAccountList();
        for (BankAccount bankAccount : accountList) {
            if (bankAccount.getAccountID().equals(accountID) ){
                if (bankAccount.getPassword().equals(password)){
                    return bankAccount;
                }
            }
        }
        return null;
    }

    @Override
    public double getBalance(BankAccount account) {
        double res = 0;
        ArrayList<BankAccount> list = accountDao.getAccountList();
        for (BankAccount bankAccount : list){
            if (bankAccount.getAccountID().equals(account.getAccountID())){
                res= bankAccount.getBalance();
            }else{
                return -1;
            }
        }
        return res;
    }




}
